﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class UnitFraction
    {
        public UnitFraction()
        {
            int[] num = new int[9];
            GetNumber(num, 0);
        }
        private void FindValue(int[] num)
        {
            int bottom = GetInt(new int[] { num[1], num[3], num[5], num[7], num[8] });
            int top = GetInt(new int[] { num[0], num[2], num[4], num[6] });
            int value = bottom / top;
            if (value * top == bottom)
            { 
                Console.WriteLine(bottom + " " + top);
            }
        }

        private void GetNumber(int[] num, int index)
        {
            
            if (index == num.Length)
            {
                FindValue(num);
            }
            for (int i = 1; i < 10; i++)
            {
                if (num.Contains(i))
                { continue; }
                else
                {
                    num[index] = i;
                    int[] numClon = new int[9];
                    num.CopyTo(numClon, 0);
                    GetNumber(numClon, index + 1);
                }
            }
        }
        private int GetInt(int[] value)
        {
            int cipher = 1;
            int returnValue = 0;
            for (int i = value.Length - 1; i >= 0; i--)
            {
                returnValue += value[i] * cipher;
                cipher *= 10;;
            }
            return returnValue;
        }
    }
}
